home *** CD-ROM | disk | FTP | other *** search
- Path: jitter.larc.nasa.gov!lance
- From: lance@jitter.larc.nasa.gov ()
- Newsgroups: comp.lang.c++
- Subject: RE: Explicit copy constructor calls illegal?
- Date: 15 Mar 1996 15:13:40 GMT
- Organization: nasa
- Distribution: world
- Message-ID: <4ic1f4$a3p@reznor.larc.nasa.gov>
- References: <4i9tp8$fgt@reznor.larc.nasa.gov> <00001a81+0000ad4e@msn.com>
- NNTP-Posting-Host: jitter.larc.nasa.gov
-
- In article <00001a81+0000ad4e@msn.com>, _GOYRA_@msn.com (David Byrden) writes:
- >
- > >> When I try to do this (just trying to re-use code - it is there, why not?),
- > >> a new instance of the class is instantiated SOMEWHERE
- >
- > Well, you didn't post your code, but be advised that explicit ctor
- > calls are not possible, no matter how much you would like to reuse
- > the code. All ctor calls are associated with the creation of a fresh
- > object. When you call the copy ctor, I guess you create a temporary
- > object, whose lifetime does not extend beyond its own statement.
- > Hence you should see the copy ctor and the dtor called for this
- > temporary object.
- >
- > David
-
- David,
-
- Yes, you are so right! I was incorrectly thinking of the Copy Constructor
- as just a Copy MAKER! The construction that I was "missing" WAS being
- echoed to me when I confirmed entry into the CC with a cout.
-
- By the way, an explicit call to the CC or any constructor IS possible, and
- is done routinely, just not the way I was trying to do it :) I have used
- the copy constructor in lieu of an overloaded operator=, like
- MyClass Myclass1;
- int Myclass1.IMyClass(/*member values, etc. */);
- MyClass Myclass2(Myclass1); // Kind of an explicit CC call.
-
- Thank you for slapping me back to reality.
-
- Michael B. Lance
- Lockheed Engineering & Sciences
- Hampton, Virginia
-